<template>
	<view class="wrap" style="padding-bottom: 60px;">
		<!-- <u-tabs :list="tabList" :is-scroll="false" :current="current" @change="change"></u-tabs> -->
		<view class="search">
			<u-icon name="scan" size="50" suffixIconStyle="color: #909399" @click="scanCode" ></u-icon>
			<u-search style="width: 100%;" v-model="queryParam.orderParams" @custom="search" @search="search"></u-search>
		</view>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" :top="top" @down="downCallback" @up="loadData">
			<view v-for="(item,index) in list" :key="item.id">
				<u-card @click="navTo('/pages/sys/workbench/materialReturnDetails',item)" class="task-list-item" :border="false" padding="20" margin="20rpx">
					<view slot="head" style="display: flex;align-items: center;justify-content: space-between;">
							<view style="display: flex;align-items: center;font-size: 30rpx;">{{item.orderNumber || ''}}</view><view style="color: #999999;font-size: 22rpx;">{{item.orderDate || ''}}</view>
						</view>
					<view class="" slot="body">
						<u-row gutter="16">
							<u-col span="12">
								<view class="apply-text"><span>项目编号：</span>{{item.projectNumber || ''}}</view>
									<view class="apply-text"><span>客户名称：</span>{{ item.customerName || '' }}</view>
									<view class="apply-text"><span>地址：</span>{{item.address || ''}}</view>
									<view class="apply-text"><span>业主电话：</span>{{item.phone || ''}}</view>
									<view class="apply-text"><span>备注：</span>{{item.remark || ''}}</view>
						<!-- 		<view style="padding: 20rpx;" v-if="current!=0">
									<image class="user-images" src="/static/aidex/images/user02.png"></image>
									<image class="user-images" src="/static/aidex/images/user03.png"></image>
								</view> -->
							</u-col>
						</u-row>
					</view>
				</u-card>
			</view>
		</mescroll-uni>
	</view>
	
</template>

<script>

import MescrollMixins from '@/components/mescroll-uni/mescroll-mixins';
import ListMxin from './mixins/ListMxin'; 
import {stringify} from '@/common/common';
export default {
	mixins:[MescrollMixins,ListMxin],
	data() {
		return {
			queryParam: {
				// status:'2,3,4'
			},
			current: 0,
			show: false,
			url:{
				list:'pickingList'
			},
			
			tabList: [{
				name: '待领取'
			}, {
				name: '已领取',
			}],
		}
	},
	
	computed: {
		top() {
			return this.CustomBar  + 46
		},
	},
	methods: {
		scanCode() {
			uni.scanCode({
				scanType: ["qrCode"],
				success: (res) => {
					console.log('success');
					let code = getQueryString(res.result,'orderNumber');
					//扫描编号
					this.queryParam.orderParams = code
					this.list = []
					this.getList({num:1,size:10})
				}, 
				fail: (res) => {
					console.log('未识别到二维码');
					this.$refs.loadinToast.hide();
				},
			})
		},
		
		/**
		 * 组装参数
		 */
		getQueryParams(){
			// if(this.current == 0){
			// 	this.queryParam.status = '3'
			// }else{
			// 	this.queryParam.status = '4,5'
			// }
		    let params = Object.assign({},this.queryParam)
			return params
		},
		change(index) {
			this.list = []
			this.current = index;
			this.queryParam.receviedStatus = index
			this.loadData({num:1,size:10})
		},
		
		navTo(url,item) {
			item.currentIndex = this.current
			let query = stringify(item)
			uni.navigateTo({
				url: `${url}?${query}` 
			});
		},
		
		/**
		 * 
		 * @param {number} page 
		 * 获取列表数据
		 */
		 getList(page) {
			let params = {
				pageNum: page.num,
				pageSize: page.size
			}
			params = Object.assign(params,this.getQueryParams())
			//联网加载数据
			this.$u.api[this.url.list](params).then(res => {
				//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
				let data = res.data.list
				//设置列表数据
				if (res.code == 200) {
					for (let annItem of data) {
						this.list.push(annItem)
					}
				}
				if (page.num == 1) {
					this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.data.list); //追加新数据
					if(this.list.length === 1){
						this.navTo('/pages/sys/workbench/pickingDetails',this.list[0])
					}
				}
				this.mescroll.endBySize(data.length,res.data.total);
			}).catch(() => {
				//联网失败, 结束加载
				this.mescroll.endErr();
			})
		},
	}
	
}
</script>

<style lang="scss" scoped>
@import 'index.scss';
page {
	background-color: #f5f5f5;
}

.wrap .search{
	padding: 20rpx;
	display: flex;
	align-items: center;
	background: #ffffff;
	width: 100%;
}
.apply-text{
	font-size: 28rpx;
	color: #333333;
	span{
		color: #999999;
	}
}
.user-images{
	width: 80px;
	height:80px;
	margin-right: 8px;
}
.apply-list-foot{
	font-size: 28rpx;
}
.personnel-list{
	display: flex;
	align-items: center;
	flex-wrap:wrap;
	.personnel-user{
		position: relative;
		margin: 5px 9px 0;
	}
	.user-images{
		width: 48px;
		height:48px;
		margin-right:0;
		
	}
	.iconfont{
		position: absolute;
		top:-12px;
		right:-5px;
		color: #FE0100;
	}
}
</style>